package intToRoman;

import java.util.ArrayList;
import java.util.List;

public class Solution {

    public static void main(String[] args) {
        System.out.println(new Solution().intToRoman(58));
    }

    public String intToRoman(int num) {
        StringBuffer roman = new StringBuffer();
        List<romans> romans = new ArrayList<romans>();
        romans.add(new romans(1, "I"));
        romans.add(new romans(5, "V"));
        romans.add(new romans(10, "X"));
        romans.add(new romans(50, "L"));
        romans.add(new romans(100, "C"));
        romans.add(new romans(500, "D"));
        romans.add(new romans(1000, "M"));


        while (num > 0) {
            for (int i = 0; i < romans.size(); i++) {
                if (num > romans.get(i).getValue()) {
                    roman.append(romans.get(i).getRoman());
                    num -= romans.get(i).getValue();
                }
            }
        }

        return roman.toString();
    }
}

class romans {
    int value;
    String roman;

    public int getValue() {
        return value;
    }

    public String getRoman() {
        return roman;
    }

    public romans(int value, String roman) {
        this.value = value;
        this.roman = roman;
    }
}
